package cn.rongdao.jrkabao.ui.cashadvance.uicomponent;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mifengkong.frtools.util.FRDisplayMetrics;

import cn.rongdao.jrkabao.R;


/**
 * Created by jiangyongxing on 2017/6/2.
 * 描述：
 */

public class CashEmptyUIComponent extends LinearLayout {

    private TextView mTextView;
    private ImageView mImageView;
    private TextView mTvAdd;

    public CashEmptyUIComponent(Context context) {
        super(context);
    }

    public CashEmptyUIComponent(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public CashEmptyUIComponent(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        mImageView = (ImageView) findViewById(R.id.lcre_iv_avatar);
        mTextView = (TextView) findViewById(R.id.lcre_tv_content);
        mTvAdd = (TextView) findViewById(R.id.icre_btn_add);
    }

    public void initTransactionecordEmpty() {
        initEmptyView("抱歉，暂时还没有信用卡取现记录。");
    }

    public void initEmptyView(String content) {
        setAvatarAndContentVisible();
        mImageView.setBackgroundResource(R.drawable.icon_record_empty);
        mTextView.setText(content);
    }

    public void initDepositCardEmpty() {
        setCardEmptyContent(false);
    }

    public void initCridetCardEmpty() {
        setCardEmptyContent(true);
    }

    private void setCardEmptyContent(boolean isCredit) {
        setAvatarAndContentVisible();
        setBackgroundColor(ContextCompat.getColor(getContext(), R.color.layout_bg));
        mImageView.setBackgroundResource(R.drawable.icon_card_empty);
        mTextView.setText(isCredit ? "抱歉，您还没有绑定信用卡。" : "抱歉，您还没有绑定储蓄卡。");
    }

    public void setAddCreditBtnText() {
        setVisibility(View.VISIBLE);
        mTvAdd.setVisibility(View.VISIBLE);
        mTvAdd.setText("+ 添加信用卡");
    }

    public void setBtnOnClickListener(OnClickListener clickListener) {
        mTvAdd.setOnClickListener(clickListener);
    }

    private void setAvatarAndContentVisible() {
        setVisibility(View.VISIBLE);
        mTextView.setVisibility(View.VISIBLE);
        mImageView.setVisibility(View.VISIBLE);
    }

    public void initCashCouponEmpty(int index) {
        setAvatarAndContentVisible();
        switch (index) {
            case 1:
                mTextView.setText("很遗憾\n您暂无可以使用的现金券");
                break;
            case 2:
                mTextView.setText("没有使用过的现金券");
                break;
            case 3:
                mTextView.setText("您还没有已失效的现金券");
                break;
        }
        mImageView.setBackgroundResource(R.drawable.icon_cash_coupon_empty);
        setBackgroundColor(ContextCompat.getColor(getContext(), R.color.layout_bg));
    }

    public void setRemindServiceEmpty() {
        setAvatarAndContentVisible();
        mTextView.setText("暂无服务");
        mImageView.setBackgroundResource(R.drawable.icon_service_empty);
    }

    public void setRemindBillEmpty() {
        setAvatarAndContentVisible();
        mTextView.setVisibility(View.GONE);
        mImageView.setBackgroundResource(R.drawable.icon_bill_empty);
        mTvAdd.setVisibility(View.VISIBLE);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, FRDisplayMetrics.dp2px(getContext(), 43));
        layoutParams.setMargins(FRDisplayMetrics.dp2px(getContext(), 60), FRDisplayMetrics.dp2px(getContext(), 20), FRDisplayMetrics.dp2px(getContext(), 60), 0);//4个参数按顺序分别是左上右下
        mTvAdd.setLayoutParams(layoutParams);
        mTvAdd.setText("导入邮箱账单");
    }
}
